FROM php:7.4.26-alpine3.13	

MAINTAINER jani <liberty_linlin@qq.com>

WORKDIR /var/www

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update && apk upgrade \
    && apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php


# apk 添加扩展依赖
# 配置 GD
# 使用 docker-php-ext-install 安装可直接安装的依赖
RUN apk add libzip-dev zlib-dev libbz2 \
        freetype-dev libpng-dev libjpeg-turbo-dev libxpm-dev \
        curl-dev openssl-dev nghttp2-dev pcre-dev c-ares-dev \
    && docker-php-ext-configure gd --enable-gd --with-jpeg --with-xpm --with-freetype \
    && docker-php-ext-install gd zip mysqli pdo_mysql bcmath iconv \
        sysvmsg sysvsem sysvshm sockets pcntl


# 添加安装包到指定目录，只支持 tar 类型的安装包，所以需要去 pecl.php.net 网站下载
# 安装编译工具
# 编译安装
# 清空安装包，无用的关联工具
#注: 因 windows 使用的是 wsl 子系统，所以需要加上 Dockerfile/ 文件夹，如果直接在 linux 运行的 docker 可以直接指向 pecl
COPY ./pecl/ /var/www/pecl/
RUN apk add gcc g++ autoconf make \
    && printf "\n" | pecl install /var/www/pecl/redis-5.3.5RC1.tgz \
    && printf "\n" | pecl install /var/www/pecl/swoole-4.8.2.tgz \
    && docker-php-ext-enable swoole redis \
    && rm -rf /var/www/pecl/ \
    && apk del autoconf make

# 设置容器时区
RUN apk add --no-cache tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && echo -e "[Date]\ndate.timezone=Asia/Shanghai" > /usr/local/etc/php/conf.d/timezone.ini


# 添加 composer 工具
COPY --from=composer:2.1.12 /usr/bin/composer /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer \
    && /usr/local/bin/composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
